package com.wyh.filemanager.model;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.os.StatFs;

import com.wyh.filemanager.util.FileUtil;
import com.wyh.log.MyLog;

public class SDCardManager {

	private static final String TAG = "SDCardManager";

	private static SDCardManager mInstance;

	public static SDCardManager getInstance() {
		if (mInstance == null) {
			mInstance = new SDCardManager();
		}
		return mInstance;
	}

	private SDCardManager() {
	}

	public void update() {
		mSDCardPaths.clear();
		if (FileUtil.isSDCardReady()) {
			File sdFile = FileUtil.getSDCardFile();
			mSDCardPaths.add(sdFile.getAbsolutePath());
			File[] files = FileUtil.getChildFiles(sdFile.getParentFile(),
					MyFileFilter.getInstance());
			for (File file : files) {
				if (file.isDirectory() && file.canWrite()) {
					StatFs stafs = new StatFs(file.getAbsolutePath());
					if (stafs.getBlockCount() > 0) {
						String path = file.getAbsolutePath();
						if (!mSDCardPaths.contains(path)) {
							mSDCardPaths.add(path);
							MyLog.debug(TAG, "update  (path = " + path + ")");
						}
					}
				}
			}
		}
	}

	List<String> mSDCardPaths = new ArrayList<String>();

}
